#include "StdAfx.h"
#include "RenderQueue.h"
#include "Renderable.h"

VAMPIRE_NAMESPACE_BEGIN

void RenderQueue::addRenderable( Renderable* obj )
{
	mRenderableMap[obj] = obj;
}

void RenderQueue::removeRenderable( Renderable* obj )
{
	if (!mRenderableMap[obj])
	{
		return;
	}
	mRenderableMap.erase(obj);
	SAFE_DELETE(obj);
}

void RenderQueue::render()
{
	RenderableMap::iterator it, itend;
	itend = mRenderableMap.end();
	for (it = mRenderableMap.begin(); it != itend; ++it)
	{
		Matrix44 transform = it->second->getWorldTransforms() * Camera::getMainCameraPtr()->getViewProjMatrix();
		it->second->getMaterial()->getEffect()->setTransformMatrix(transform);
		it->second->getMaterial()->getEffect()->commitChanges();
		it->second->draw();
	}
}

VAMPIRE_NAMESPACE_END
